{include file="common/_header"}

<body>

<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">商品描述</label>
                <div class="layui-input-inline" style="width: 80%;">

                        <textarea class="layui-textarea" placeholder="请输内容"
                                  name="describe" lay-verify="content"
                                  id="lay_edit" style="border: 2px;">{$data.data.describe}</textarea>

                </div>
            </div>
        </div>
    </form>
</div>
</body>


<script>
    layui.use('upload', function() {
        var upload = layui.upload;
        var id = 3;
        var id2 = 3;
        var number = 0;
        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/main/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , before: function (obj) {
                number = $('.layui-upload-list').find('img').length;
                if(number > 1){
                    layer.msg('最多只能上传一张图片');
                    return false;
                }
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    // console.log(result);
                    // $('#demo1').attr('src', result); //图片链接（base64）
                    $('.layui-upload-list').find("img").remove();
                    $('.layui-upload-list').append('<img class="layui-upload-img" id="demo'+id+'" width="100px" height="100px" src="'+result+'" ondblclick="delimg('+id+')" style="margin-right:5px;">')
                    id += 1;
                });

                // element.progress('demo', '0%'); //进度条复位
                // layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                console.log(res);
                if(number >= 3){return false;}
                //如果上传失败
                if(res.code = 1){
                    // $('.layui-upload-list').append('<input type="hidden" name="imageurl[]" class="image'+id2+'"  value="'+res.data+'" lay-verify="required">')
                    $('.layui-upload-list').append('<input type="hidden" name="imageurl" class="image'+id2+'"  value="'+res.data+'" lay-verify="required">')
                    id2 += 1;
                    // $('.image').attr('value', res.data);
                    // return layer.msg('上传成功');
                }
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
    });
    function delimg(id){
        $('.layui-upload-list').find('#demo'+id).remove();
        $('.layui-upload-list').find('.image'+id).remove();
    }
</script>

<script>
    layui.use(['layedit', 'form'], function () {

        var form = layui.form;
        var layedit = layui.layedit;
        var up_url = "{:url('/main/ueditor')}";
        layedit.set({
            //暴露layupload参数设置接口 --详细查看layupload参数说明
            uploadImage: {
                url: up_url //接口url
                , type: 'post' //默认post
                , accept: 'image'
                , acceptMime: 'image/*'
                , exts: 'jpg|png|gif|bmp|jpeg'
            }
            , devmode: true
            //插入代码设置
            , codeConfig: {
                hide: true,  //是否显示编码语言选择框
                default: 'javascript' //hide为true时的默认语言格式
            }
            , tool: [
                'strong' //加粗
                , 'italic' //斜体
                , 'underline' //下划线
                , 'del' //删除线

                , '|' //分割线

                , 'left' //左对齐
                , 'center' //居中对齐
                , 'right' //右对齐
                , 'link' //超链接
                , 'unlink' //清除链接
                // , 'face' //表情
                , 'image' //插入图片
                , 'help' //帮助

            ]
            , height: 300, //设置编辑器高度
        });

        var index = layedit.build('lay_edit', {
            width: 600,
            height: 300, //设置编辑器高度
        });   //建立编辑器

        //提交时把值同步到文本域中
        form.verify({
            //content富文本域中的lay-verify值
            content: function (value) {
                return layedit.sync(index);
            }
        });


        form.on('submit(add)', function (data) {

            // data.field.detail = layui.layedit.getContent(index);

            $.ajax({
                'url': '/products/boxeproduct',
                'type': 'post',
                'data': data.field,
                'dataType': 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 800,
                        }, function () {
                            window.parent.location.href = data.url;
                        })
                    } else if (data.code == 0) {
                        layer.msg(data.msg);
                    }
                }
            });
        });

    });


</script>

{include file="common/_bottom"}